home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / PROGRAMR / GSRC208A.ZIP / GWTOP.C < prev    next >
C/C++ Source or Header  |  1993-08-26  |  26KB  |  704 lines

  1. #include "copyleft.h"
  2.  
  3. /*
  4.     GEPASI - a simulator of metabolic pathways and other dynamical systems
  5.     Copyright (C) 1989, 1992  Pedro Mendes
  6. */
  7.  
  8. /*************************************/
  9. /*                                   */
  10. /*          GWTOP - Topology         */
  11. /*        MS-WINDOWS front end       */
  12. /*                                   */
  13. /*           Topology window         */
  14. /*                                   */
  15. /*           QuickC/WIN 1.0          */
  16. /*                                   */
  17. /*   (include here compilers that    */
  18. /*   compiled GWSIM successfully)    */
  19. /*                                   */
  20. /*************************************/
  21.  
  22.  
  23. /*
  24.   be sure that IOTOP.C is recompiled and that
  25.   it iotop.obj from a GWSIM compilation is not
  26.   being used now. To be sure, delete iotop.obj
  27. */
  28.  
  29. /* this is needed for IOTOP.C */
  30. #define GWTOP
  31.  
  32. #include <windows.h>
  33. #include <string.h>
  34. #include "commdlg.h"
  35. #include "basic.h"                        /* basic windows fnction prototypes        */
  36. #include "defines.h"                    /* symbols also used in .DLG files        */
  37. #include "globals.h"                    /* gepasi's own symbols                    */
  38. #include "gwtop.h"                        /* macros, function prototypes, etc.    */
  39. #include "gep1.h"                        /* gepasi's variables                    */
  40. #include "strtbl.h"                        /* symbols for the string table            */
  41. #include "iotop.h"
  42.  
  43. #pragma alloc_text( CODE0, WinMain, WndProc, AboutBox, nCwRegisterClasses, CwUnRegisterClasses, CleanUp )
  44.  
  45. #define HELP_PARTIALKEY   0x0105
  46.  
  47.  
  48. /* Struct pointed to by WM_GETMINMAXINFO lParam
  49. typedef struct tagMINMAXINFO
  50. {
  51.     POINT ptReserved;
  52.     POINT ptMaxSize;
  53.     POINT ptMaxPosition;
  54.     POINT ptMinTrackSize;
  55.     POINT ptMaxTrackSize;
  56. } MINMAXINFO;
  57. */
  58.  
  59. /* global variables    */
  60. char szString[128];   /* variable to load resource strings         */
  61. char szHelpFile[] = "GEPASI.HLP";                    /* help file name                        */
  62. char szAppName[20];   /* class name for the window                    */
  63. int  lbWidth;         /* width of largest string in list box        */
  64. HWND            hInst;
  65. HWND            hWndMain;
  66. HCURSOR            hHourGlass;                /* handle to the wait cursor            */
  67. HMENU            hMenu;                    /* handle to the menu                    */
  68. GLOBALHANDLE    hMetn;                    /* handle to memory block w/ metn        */
  69. GLOBALHANDLE    hStepn;                    /* handle to memory block w/ stepn        */
  70. GLOBALHANDLE    hSto;                    /* handle to memory block w/ sto        */
  71. GLOBALHANDLE    hLp;                    /* handle to memory block w/ lp            */
  72. GLOBALHANDLE    hKinet;                    /* handle to memory block w/ kinet        */
  73. GLOBALHANDLE    hRs;                    /* handle to memory block w/ ord        */
  74. char            (huge *metn)[NAME_L];    /* pointer to work with metname array    */
  75. char            (huge *stepn)[NAME_L];    /* pointer to work with step names        */
  76. unsigned
  77.  char (huge *lp)[MAX_STEP][MAX_MET];    /* def. of modification loops            */
  78. int   (huge *rs)[MAX_STEP][MAX_MOL];    /* reaction structure                    */
  79. int                huge *sto;                /* pointer to work with metname array    */
  80. int                totm;                    /* number of total metabolites            */
  81. int                nst;                    /* number of steps                        */
  82. int                nlps;                    /* number of reactions with modifiers    */
  83. int                intm[MAX_MET];            /* 1 if internal metabolite                */
  84. unsigned char    rvr[MAX_STEP];            /* 1 if reaction is reversible            */
  85. int             huge *kinet;            /* pointer to mirror of kinetu            */
  86. unsigned char    nmd[MAX_STEP];            /* number of assigned modfs of a react.    */
  87. int                kinass, kass;            /* number of reactions w/ defined type    */
  88. int                loopass, lass;            /* number of reactions w/ defined modif.*/
  89. int             notsaved;                /* 1 if file has not been saved            */
  90. int                eqefl;                    /* 1 if editing existing u-d rate eq.    */
  91. char            FileName[256];            /* filename of file with full path        */
  92. char            FileTitle[13];            /* filename of file w/o full path        */
  93. char            errstr[80];                /* string to hold lex and parser errors    */
  94. unsigned char    lex;                    /* index for parser                        */
  95.  
  96. int PASCAL WinMain(HANDLE hInstance, HANDLE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow)
  97. {
  98.  /***********************************************************************/
  99.  /* HANDLE hInstance;       handle for this instance                    */
  100.  /* HANDLE hPrevInstance;   handle for possible previous instances      */
  101.  /* LPSTR  lpszCmdLine;     long pointer to exec command line           */
  102.  /* int    nCmdShow;        Show code for main window display           */
  103.  /***********************************************************************/
  104.  
  105.  MSG        msg;           /* MSG structure to store your messages        */
  106.  int        nRc;           /* return value from Register Classes          */
  107.  HANDLE        hAcc;
  108.  LPSTR        ptr;
  109.  
  110.  strcpy(szAppName, "GWTOP");
  111.  hInst = hInstance;
  112.  if(!hPrevInstance)
  113.    {
  114.     /* register window classes if first instance of application         */
  115.     if ((nRc = nCwRegisterClasses()) == -1)
  116.       {
  117.        /* registering one of the windows failed                         */
  118.        LoadString(hInst, IDS_ERR_REGISTER_CLASS, szString, sizeof(szString));
  119.        MessageBeep( MB_ICONHAND );
  120.        MessageBox(NULL, szString, NULL, MB_ICONSTOP);
  121.        return nRc;
  122.       }
  123.    }
  124.  
  125.  /* setup the device independent screen units    */
  126.  InitScrScale();
  127.  
  128.  /* load the wait cursor                        */
  129.  hHourGlass = LoadCursor(NULL, IDC_WAIT);
  130.  
  131.  /* load the accelerators table    */
  132.  hAcc = LoadAccelerators( hInst, (LPSTR) "ACCTABLE" );
  133.  
  134.  /* create application's Main window                                    */
  135.  hWndMain = CreateWindow(
  136.                 szAppName,               /* Window class name           */
  137.                 "GEPASI - Topology",     /* Window's title              */
  138.                 WS_CAPTION      |        /* Title and Min/Max           */
  139.                 WS_SYSMENU      |        /* Add system menu box         */
  140.                 WS_MINIMIZEBOX  |        /* Add minimize box            */
  141.                 WS_CLIPCHILDREN |        /* don't draw in child windows areas */
  142.                 WS_OVERLAPPED,
  143.                 CW_USEDEFAULT, 0,        /* Use default X, Y            */
  144.                 ScrX(150), ScrY(90),
  145.                 NULL,                    /* Parent window's handle      */
  146.                 NULL,                    /* Default to Class Menu       */
  147.                 hInst,                   /* Instance of window          */
  148.                 NULL);                   /* Create struct for WM_CREATE */
  149.  
  150.  
  151.  if(hWndMain == NULL)
  152.  {
  153.   LoadString(hInst, IDS_ERR_CREATE_WINDOW, szString, sizeof(szString));
  154.   MessageBeep( MB_ICONHAND );
  155.   MessageBox(NULL, szString, NULL, MB_ICONSTOP);
  156.   return IDS_ERR_CREATE_WINDOW;
  157.  }
  158.  
  159.  if( InitGepasiVar() != 0 )                    /* initialize GEPASI's vars */
  160.  {
  161.   LoadString(hInst, IDS_ERR_OUT_OF_MEM, szString, sizeof(szString));
  162.   MessageBeep( MB_ICONHAND );
  163.   MessageBox(NULL, szString, NULL, MB_ICONSTOP);
  164.   if(!hPrevInstance) CwUnRegisterClasses();
  165.   return IDS_ERR_OUT_OF_MEM;
  166.  }
  167.  /* lets allocate memory for mirror of metname    */
  168.  hMetn = GlobalAlloc( GMEM_MOVEABLE | GMEM_ZEROINIT, (DWORD) MAX_MET * NAME_L * sizeof( char ) );
  169.  if( hMetn == NULL )
  170.  {
  171.   LoadString(hInst, IDS_ERR_OUT_OF_MEM, szString, sizeof(szString));
  172.   MessageBeep( MB_ICONHAND );
  173.   MessageBox(NULL, szString, NULL, MB_ICONSTOP);
  174.   CleanUp(hWndMain, hPrevInstance);
  175.   return IDS_ERR_OUT_OF_MEM;
  176.  }
  177.  hStepn = GlobalAlloc( GMEM_MOVEABLE | GMEM_ZEROINIT, (DWORD) MAX_STEP * NAME_L * sizeof( char ) );
  178.  if( hStepn == NULL )
  179.  {
  180.   LoadString(hInst, IDS_ERR_OUT_OF_MEM, szString, sizeof(szString));
  181.   MessageBeep( MB_ICONHAND );
  182.   MessageBox(NULL, szString, NULL, MB_ICONSTOP);
  183.   GlobalFree( hMetn );
  184.   CleanUp(hWndMain, hPrevInstance);
  185.   return IDS_ERR_OUT_OF_MEM;
  186.  }
  187.  /* lets allocate memory for mirror of stoiu    */
  188.  hSto = GlobalAlloc( GMEM_MOVEABLE | GMEM_ZEROINIT, (DWORD) MAX_MET * MAX_STEP * sizeof( int ) );
  189.  if( hSto == NULL )
  190.  {
  191.   LoadString(hInst, IDS_ERR_OUT_OF_MEM, szString, sizeof(szString));
  192.   MessageBeep( MB_ICONHAND );
  193.   MessageBox(NULL, szString, NULL, MB_ICONSTOP);
  194.   GlobalFree( hStepn );
  195.   GlobalFree( hMetn );
  196.   CleanUp(hWndMain, hPrevInstance);
  197.   return IDS_ERR_OUT_OF_MEM;
  198.  }
  199.  /* mirror of loop                                */
  200.  hLp = GlobalAlloc( GMEM_MOVEABLE | GMEM_ZEROINIT, (DWORD) MAX_STEP * MAX_MET * sizeof( unsigned char ) );
  201.  if( hLp == NULL )